﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace HoluxConvertorCore
{
    public delegate void ConvertProgress(int Perc);

    public class GpxLog
    {
        private List<String> Log;
        private String LogName;

        public GpxLog(List<string> FileLog, String Name)
        {
            Log = FileLog;

            LogName = Name;
        }

        public GpxLog()
        {
            Log = null;

            LogName = null;
        }

        public String Name
        { 
            get
            {
                return LogName;
            }
        }


        public List<String> GpxLogConvert(ConvertProgress ReportProgressFunc)
        {
            List<String> ConvertedLog = new List<string>();
            int i = 0;
            String Line = "";

            int progressIndex = 100;

            Line = Log[i];
            do
            {
                if (Line.Contains("<ele>") || (Line.Contains("<desc>")) || (Line.Contains("<speed>")))
                {
                }
                else
                {
                    ConvertedLog.Add(Line);
                }
                i++;
                Line = Log[i];

                if (progressIndex != (i * 100 / Log.Count))
                {
                    progressIndex = (i * 100 / Log.Count);

                    ReportProgressFunc(progressIndex);

                    System.Threading.Thread.Sleep(10);
                }
            }
            while (Line != null);

            ReportProgressFunc(100);

            ConvertedLog[1] = @"<gpx xmlns=""http://www.topografix.com/GPX/1/1"" version=""1.1"" creator=""Mobile Trail Explorer"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"" >";

            return ConvertedLog;
        }
    }
}
